**Curtis RESTAT
**Table 3 Panel A regressions
**Change to directory where data and code were downloaded
**cd 
*ssc install estout


clear all
set matsize 9000
set maxvar 9000

use cbp_cty_table3,clear


do datacleancty_table3.do
rename state stateabb
rename fipstate state
so state year



drop if year==2009
replace trend=year-1997
qui tab naics,gen(ind)

forvalues i = 1(1)21 {
   qui replace ind`i'= ind`i'*trend
}

forvalues i = 1(1)21 {
   qui rename ind`i' indtrend`i'
 }

 

qui tab state,gen(STdum)

foreach x of varlist STdum1-STdum49 {
  qui gen trend`x'=`x'*trend
  }

  
so ctyind year
gen empweight2=emp_imp if year==1998
bysort ctyind:carryforward empweight2,replace
drop if emp==.
qui tab year,gen(y)
gen NBPstr="NBP" if NBP==1
replace NBPstr="west" if NBPstr==""
gen NBPind=NBPstr+naics

*Column 1
qui eststo: qui areg  lemp_imp postxNBPxint postxNBP postxint intxNBP  y1-y11[aweight=empweight2], abs(ctyind) rob cluster(NBPind)
*Column 2
qui tab yearind,gen(yi)
qui eststo: qui areg  lemp_imp postxNBPxint postxNBP postxint intxNBP yi* trendSTdum* [aweight=empweight2], abs(ctyind) rob cluster(NBPind)
*Column 3
qui eststo: qui areg  lemp_imp postxNBPxint postxNBP postxint intxNBP  y1-y11 indtrend* trendSTdum* [aweight=empweight2], abs(ctyind) rob cluster(NBPind)
	*Gen E/W trends
	forvalues i = 1(1)21 {
	   qui gen eindtrend`i' = indtrend`i'*NBP
	  }

	forvalues i = 1(1)21 {
	   qui gen windtrend`i' = indtrend`i'*((NBP-1)^2)
	  }
*Column 4
qui eststo: qui areg  lemp_imp postxNBPxint postxNBP postxint intxNBP windtrend* eindtrend* y1-y11 [aweight=empweight2], abs(ctyind) rob cluster(NBPind)
*Column 5
qui eststo: qui areg  lemp_imp postxNBPxint postxNBP postxint intxNBP windtrend* eindtrend* y1-y11 indtrend* trendSTdum* [aweight=empweight2], abs(ctyind) rob cluster(NBPind)
*Column 6
qui eststo: qui areg  lemp_imp postxNBPxint postxNBP postxint intxNBP windtrend* eindtrend* yi* trendSTdum* [aweight=empweight2], abs(ctyind) rob cluster(NBPind)

outreg2 [est1 est2 est3 est4 est5 est6] using "table3a.rtf",keep(postxNBPxint postxNBP) nocons replace

